﻿-- =============================================
-- Author:			Nicolas Lareu
-- Create date:		<MMMM> <DD>, <YYYY>
-- Description:		<Description>
-- =============================================
CREATE FUNCTION CFL.GetConfigVariable
(
	@configVariableName VARCHAR(50) = NULL
)
RETURNS VARCHAR(MAX)
AS
BEGIN
	SET @configVariableName = LTRIM(RTRIM(@configVariableName))

	RETURN CASE WHEN ((@configVariableName IS NULL) AND (@configVariableName = ''))
				THEN NULL
				ELSE 
				(
					SELECT 
						TOP 1 
						LTRIM(RTRIM(c.Value))
					FROM CFL.Config c 
					WHERE 
						LTRIM(RTRIM(c.Name)) = @configVariableName
				)
			END
END

GO
GRANT EXECUTE
    ON OBJECT::CFL.GetConfigVariable TO [SystemPublic]
    AS [dbo];
